import request from "../../utils/request";

// pages/personal/personal.js
let startY = 0;
let endY = 0;
let dis = 0;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dis: '0rpx',
    transtion: '',
    userInfo: {},
    recentList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let userInfo = wx.getStorageSync('userInfo')
    if (userInfo) {
      this.setData({
        userInfo
      })
      this.getRecodList()
    }

  },

  async getRecodList() {
    let res = await request('/user/record', {
      uid: this.data.userInfo.userId,
      type: 0
    })
    let index = 0
    this.setData({
      recentList: res.allData.map(item => ({
        ...item,
        id: index++
      }))
    })
  },

  touchstart(e) {
    startY = e.touches[0].clientY;
    this.setData({
      transtion: ''
    })
  },
  touchmove(e) {
    endY = e.touches[0].clientY;
    dis = endY - startY
    if (dis < 0) dis = 0
    if (dis > 80) dis = 80
    this.setData({
      dis: dis + 'rpx'
    })
  },
  touchend() {
    this.setData({
      dis: 0 + 'rpx',
      transtion: 'transition: all 1s linear;'
    })
  },

  goLogin() {
    if (this.data.userInfo.nickname) {
      return;
    }
    wx.navigateTo({
      url: '/pages/login/login'
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})